<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class BusOrders extends Base
{
    protected $insert = ['addtime'];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }
    public function getPayTimeTextAttr($value, $data){
        return date('Y-m-d H:i:s', $data['pay_time']);
    }
    public function getAddtimeTextAttr($value, $data){
        return date('Y-m-d H:i:s', $data['addtime']);
    }
    public function getGoodsTextAttr($value,$data){
            $bus = (new \app\common\model\BusOrdersGoods())->where(['orders_id' => $data['id']])->group('bus_id')->column('bus_id');
            $arr = [];
            // foreach ($bus as $key => $val) {
            //     $goods = (new \app\common\model\BusOrdersGoods())
            //     ->where(['orders_id' => $data['id'],'bus_id' => $val])
            //     ->field(['goods_sku_id','goods_title','goods_sku_title','goods_money','coupon_money','num','img','bus_id','goods_id'])
            //     ->select();
            //     $arr[$key]['bus'] =  (new \app\common\model\Bus())->where(['id' => $val])->field(['id','nickname'])->find();
            //     $arr[$key]['bus']['goods_count'] = count($goods);
            //     $arr[$key]['bus']['goods'] = $goods;
            // }
            $goods = (new \app\common\model\BusOrdersGoods())
                ->where(['orders_id' => $data['id']])
                ->field(['goods_sku_id','goods_title','goods_sku_title','goods_money','coupon_money','num','img','bus_id','goods_id'])
                ->select();
         
         return $goods;
           
    }
    public function getManageNameTextAttr($value,$data){
        return (new \app\common\model\UserManage())->where(['id' => $data['manage_id']])->value('nickname');
    }
}
